//
//  UIBarButtonItem+navItem.m
//  TopicDemo
//
//  Created by InitialC on 16/11/24.
//  Copyright © 2016年 InitialC. All rights reserved.
//

#import "UIBarButtonItem+navItem.h"
#import "ZWToolHeader.h"

@implementation UIBarButtonItem (navItem)

+ (instancetype)navLItemWithImage:(UIImage *)image highlightImage:(UIImage *)highlightImage addTarget:(id)target action:(SEL)action {
    
    UIButton *itemButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [itemButton setImage:image forState:UIControlStateNormal];
    [itemButton setImage:highlightImage forState:UIControlStateHighlighted];
    [itemButton sizeToFit];
//    itemButton.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 6);
    [itemButton addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    UIView *containView = [[UIView alloc] initWithFrame:itemButton.bounds];
    [containView addSubview:itemButton];
    return [[UIBarButtonItem alloc] initWithCustomView:containView];
}
+ (instancetype)navRItemWithImage:(UIImage *)image highlightImage:(UIImage *)highlightImage addTarget:(id)target action:(SEL)action {
    UIButton *itemButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [itemButton setImage:image forState:UIControlStateNormal];
    [itemButton setImage:highlightImage forState:UIControlStateHighlighted];
    [itemButton sizeToFit];
    [itemButton setHitTestEdgeInsets:UIEdgeInsetsMake(-20, -20, -8, -8)];
//    itemButton.imageEdgeInsets = UIEdgeInsetsMake(0, 6, 0, 0);
    [itemButton addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
//    UIView *containView = [[UIView alloc] initWithFrame: CGRectMake(0, 0, 50, 50)];
//    [containView addSubview:itemButton];
    return [[UIBarButtonItem alloc] initWithCustomView:itemButton];
}
+ (instancetype)navItemWithImage:(UIImage *)image selImage:(UIImage *)selImage addTarget:(id)target action:(SEL)action {
    
    UIButton *itemButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [itemButton setImage:image forState:UIControlStateNormal];
    [itemButton setImage:selImage forState:UIControlStateSelected];
    [itemButton sizeToFit];
    [itemButton addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    
    UIView *containView = [[UIView alloc] initWithFrame:itemButton.bounds];
    
    [containView addSubview:itemButton];
    return [[UIBarButtonItem alloc] initWithCustomView:containView];
}


@end
